package hmm;

import static org.junit.Assert.*;

import java.util.LinkedList;

import org.junit.Test;

/**
 * This tests the Viterby Algorithm implementation
 * 
 * @author Amit Yungman
 */
public class ViterbyTest {
  private Hmm _hmm;
  private Viterby _viterby;
  private ViterbyResult _result;
  final double ERROR_RANGE = 0.0000000001;
  
  @Test
  public void setUp1() {
    double[][] a = new double[][]{new double[]{0.5,0.25,0.25},new double[]{0.375,0.125,0.375},new double[]{0.125,0.675,0.375}};
    double[][] b = new double[][]{new double[]{0.6,0.2,0.15,0.05},new double[]{0.25,0.25,0.25,0.25},new double[]{0.05,0.1,0.35,0.5}};
    double[] pi = new double[]{0.63,0.17,0.2};
    LinkedList<String> baseWords = new LinkedList<String>();
    baseWords.add("Dry");
    baseWords.add("Dryish");
    baseWords.add("Damp");
    baseWords.add("Soggy");
    LinkedList<String> tags = new LinkedList<String>();
    tags.add("Sunny");
    tags.add("Cloudy");
    tags.add("Rainy");
    _hmm = new Hmm(tags,baseWords,pi,a,b);
    assertNotNull(_hmm);
    _viterby = new Viterby(_hmm);
    assertNotNull(_viterby);
  }
  
  @Test
  public void testWithRealValues() {
    setUp1();
    _result = _viterby.calculateViterby(new String[]{"Dry","Damp","Soggy"});
    assertNotNull(_result);
    assertEquals(_result.path[0], "Sunny");
    assertEquals(_result.path[1], "Rainy");
    assertEquals(_result.path[2], "Rainy");
    assertTrue(_result.p - 0.0062015625 <= 0.0000000001);
  }

  @Test
  public void testWithRealValues2() {
    setUp1();
    _result = _viterby.calculateViterby(new String[]{"Dry","Dry","Soggy","Dry","Dry","Soggy"});
    assertNotNull(_result);
    assertEquals(_result.path[0], "Sunny");
    assertEquals(_result.path[1], "Sunny");
    assertEquals(_result.path[2], "Rainy");
    assertEquals(_result.path[3], "Cloudy");
    assertEquals(_result.path[4], "Sunny");
    assertEquals(_result.path[5], "Rainy");
    assertTrue(_result.p - 0.00006727589 <= 0.0000000001);
  }
}
